package com.fruit.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RetryRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @Description: ribbon配置
 * @Author: LJ
 * @Date: 2018/10/31 11:02
 * @version:
 */
@Component
public class LoadBalancedConfig {
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean
    public IRule ribbonRule() {
        //return new RoundRobinRule();                //轮训
        //return new WeightedResponseTimeRule();    //加权权重
        return new RetryRule();                    //带有重试机制的轮训
        //return new RandomRule();                   //随机
        //return new CustomRule();                     //自定义规则
    }
}